import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getListRole } from '/@/api/system/system';
import componentSetting from '/@/settings/componentSetting';
import { isArray } from '/@/utils/is';
import { h } from 'vue';
import { Checkbox } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    title: '',
    dataIndex: 'seq',
    width: 50,
    ellipsis: true,
    resizable: false,
    slots: {
      customRender: 'move',
    },
    customCell: (record, rowIndex, column) => {
      return {
        style: {
          cursor: 'move',
        },
      };
    },
  },
  {
    title: '用户',
    dataIndex: 'desc',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  //   {
  //     title: '发起',
  //     dataIndex: 'see',
  //     width: 50,
  //     ellipsis: true,
  //     resizable: true,
  //     customRender: ({ record, column }) => {
  //       return h(Checkbox, {
  //         checked: record['see'] == 1 ? true : false,
  //         onChange: (e) => {
  //           record['see'] = e.target.checked ? 1 : 0;
  //         },
  //       });
  //     },
  //   },
  //   {
  //     title: '查询',
  //     dataIndex: 'modify',
  //     width: 80,
  //     ellipsis: true,
  //     resizable: true,
  //     customRender: ({ record }) => {
  //       return h(Checkbox, {
  //         checked: record['modify'] == 1 ? true : false,
  //         onChange: (e) => {
  //           record['modify'] = e.target.checked ? 1 : 0;
  //         },
  //       });
  //     },
  //   },
  //   {
  //     title: '管理',
  //     dataIndex: 'examine',
  //     width: 100,
  //     ellipsis: true,
  //     resizable: true,
  //     customRender: ({ record }) => {
  //       return h(Checkbox, {
  //         checked: record['examine'] == 1 ? true : false,
  //         onChange: (e) => {
  //           record['examine'] = e.target.checked ? 1 : 0;
  //         },
  //       });
  //     },
  //   },
  //   {
  //     title: '督办',
  //     dataIndex: 'append',
  //     width: 100,
  //     ellipsis: true,
  //     resizable: true,
  //     customRender: ({ record }) => {
  //       return h(Checkbox, {
  //         checked: record['append'] == 1 ? true : false,
  //         onChange: (e) => {
  //           record['append'] = e.target.checked ? 1 : 0;
  //         },
  //       });
  //     },
  //   },
  {
    title: '类型',
    dataIndex: 'typeDesc',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '权限',
    dataIndex: 'authority',
    width: 650,
    ellipsis: true,
    resizable: true,
    slots: {
      customRender: 'authority',
    },
  },
  {
    title: '过滤',
    dataIndex: 'isFilter',
    width: 60,
    ellipsis: true,
    resizable: true,
    customRender: ({ record }) => {
      return h(Checkbox, {
        checked: record['isFilter'] == 1 ? true : false,
        title: '启用过滤条件',
        onChange: (e) => {
          record['isFilter'] = e.target.checked ? 1 : 0;
        },
      });
    },
  },
  {
    title: '过滤条件',
    dataIndex: 'filterCond',
    width: 100,
    ellipsis: true,
    resizable: true,
    slots: {
      customRender: 'filterCond',
    },
  },
  {
    title: '可写字段',
    dataIndex: 'fieldWrite',
    width: 100,
    ellipsis: true,
    resizable: true,
    slots: {
      customRender: 'fieldWrite',
    },
  },
  {
    title: '隐藏字段',
    dataIndex: 'fieldHide',
    width: 100,
    ellipsis: true,
    resizable: true,
    slots: {
      customRender: 'fieldHide',
    },
  },
  {
    title: '可导字段',
    dataIndex: 'fieldExport',
    width: 100,
    ellipsis: true,
    resizable: true,
    slots: {
      customRender: 'fieldExport',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'title',
    label: '标题',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'title1',
    label: '角色',
    required: true,
    component: 'Select',
    colProps: { span: 24 },
    componentProps: async ({ formActionType }) => {
      let options =
        (await getListRole({ pageSize: 99999 }))[componentSetting.table.fetchSetting.listField] ||
        [];
      if (!isArray(options)) {
        options = [];
      }
      const obj = {
        options,
        mode: 'multiple',
        fieldNames: { label: 'description', value: 'code', key: 'code' },
        getPopupContainer: () => document.body,
      };
      const { updateSchema } = formActionType;

      updateSchema([
        {
          field: 'title1',
          componentProps: obj,
        },
      ]);

      return obj;
    },
  },
  {
    field: 'title3',
    label: '用户名',
    required: true,
    component: 'SelectUserInput',
    colProps: { span: 24 },
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        type: 1,
        onChange: (value, record) => {
          console.log('value,e', value, record);
          formModel['newUserName'] = record.dataRef.userNames || '';
          console.log({ schema, tableAction, formActionType, formModel });
        },
      };
    },
  },
  {
    field: 'newUserName',
    label: 'newUserName',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
    show: false,
  },
];

export const authorityList = [
  {
    label: '浏览',
    value: 'see',
    message: '浏览列表',
  },
  {
    label: '查看',
    value: 'view',
    message: '查看详情及流程',
  },
  {
    label: '添加',
    value: 'append',
    message: '添加记录',
  },
  {
    label: '修改',
    value: 'modify',
    message: '修改记录',
  },
  {
    label: '删除',
    value: 'del',
    message: '删除记录',
  },
  {
    label: '生成',
    value: 'exportWord',
    message: '生成Word文件',
  },
  {
    label: '导入',
    value: 'import',
    message: '导入Excel文件',
  },
  {
    label: '导出',
    value: 'export',
    message: '导出Excel文件',
  },
  {
    label: '列表',
    value: 'setList',
    message: '设置列表中的字段及排序',
  },
  {
    label: '变更',
    value: 'reActive',
    message: '变更记录',
  },
  {
    label: '日志',
    value: 'log',
    message: '管理日志',
  },
  {
    label: '打包',
    value: 'zip',
    message: '打包下载文件',
  },
  {
    label: '复制',
    value: 'copy',
    message: '复制记录',
  },
  {
    label: '回滚',
    value: 'rollBack',
    message: '回滚流程及记录',
  },
  {
    label: '管理',
    value: 'manage',
    message: '可添加、修改、删除记录、导入、导出、管理日志',
  },
  {
    label: '数据',
    value: 'data',
    message: '数据维护，不受校验规则限制',
  },
  {
    label: '选择列导出',
    value: 'exportXlsCol',
    message: '选择列导出',
  },
];
